/* forkexectest.c
 *	Simple program to test whether running a user program works.
 *	
 *	Just do a "syscall" that shuts down the OS.
 *
 * 	NOTE: for some reason, user programs with global data structures 
 *	sometimes haven't worked in the Nachos environment.  So be careful
 *	out there!  One option is to allocate data structures as 
 * 	automatics within a procedure, but if you do this, you have to
 *	be careful to allocate a big enough stack to hold the automatics!
 */

#include "syscall.h"
int lock0;
int lockMain;
int condition0;
int conditionMain;


void thread1() {
	Write("Thread 1 running.\n", 19, ConsoleOutput);
	/*Acquire(lock0);
	Wait(condition0, lock0);
	Release(lock0);*/
	Exit(0);
}

void thread2() {
	Write("Thread 2 running.\n", 19, ConsoleOutput);
	/*Acquire(lock0);
	Signal(condition0, lock0);
	Acquire(lockMain);
	Signal(conditionMain, lockMain);
	Release(lockMain);
	Release(lock0);*/
	Exit(0);
}

void thread3() {
	Write("Thread 3 running.\n", 19, ConsoleOutput);
	Exit(0);
}


int
main()
{
	Write("Starting test Fork and Exec\n", 29, ConsoleOutput);
	
	/*lock0 = CreateLock("Lock0", 5);
	lockMain = CreateLock("LockMain", 8);
	
	condition0 = CreateCondition("Condition0", 10);
	conditionMain = CreateCondition("ConditionMain", 13);*/
	
	Fork(thread1);
	Write("Forked thread 1.\n", 18, ConsoleOutput);
	/*Acquire(lockMain);*/
	Fork(thread2);
	Write("Forked thread 2.\n", 18, ConsoleOutput);
	/*Wait(conditionMain, lockMain);*/

	/*Fork(thread3);
	Release(lockMain);*/
    /*Halt();*/
	return 0;
    /* not reached */
}
